package main

import (
	"bufio"
	"bytes"
	"encoding/binary"
	"fmt"
	"net/smtp"
	"os"
	"strconv"
	"strings"
	"time"
)

const (
	EMAIL_SMTP_CONTENT_TYPE_TEXT = "Content-Type: text/plain; charset=UTF-8"
	EMAIL_SMTP_CONTENT_TYPE_HTML = "Content-Type: text/html; charset=UTF-8"
	smtp_username                = `edm@wo.cn`
	smtp_email                   = `edm@wo.cn`
	smtp_password                = `1qaz2wsx`
	smtp_host                    = `smtp.wo.cn:25`
)

func SendEMailInSmtp(user string, password string, host string, to string, subject string, body string) error {
	hp := strings.Split(host, ":")
	auth := smtp.PlainAuth("", user, password, hp[0])
	content_type := EMAIL_SMTP_CONTENT_TYPE_TEXT
	content_type = EMAIL_SMTP_CONTENT_TYPE_HTML

	msg := []byte("To: " + to + "\r\nFrom: " + user + "<" + user + ">\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + body)
	send_to := strings.Split(to, ";")
	err := smtp.SendMail(host, auth, user, send_to, msg)
	return err
}
func testFileHd() {
	fuck, _ := os.Open("/hdd1/fuck.txt")
	suck, _ := os.Open("/hdd1/suck.txt")
	time.Sleep(time.Second * 1000)
	fuck.Close()
	suck.Close()
}

func ip2int(ip string) (res int) {
	segs := strings.Split(ip, ".")
	b := 24
	for i := range segs {
		t, err := strconv.ParseInt(segs[i], 10, 32)
		if err != nil {

		}
		t1 := uint(t)
		res += int(t1 << uint(b-i*8))
	}
	return
}
func testPrintf() {
	var scanner = bufio.NewScanner(os.Stdin)
	fmt.Println("one")
	fmt.Println("two")
	for ; scanner.Scan(); fmt.Println("please input: ") {
		if scanner.Text() == "clear" {
			fmt.Printf("\033[2J")
		}
		if scanner.Text() == "up" {
			fmt.Printf("\033[%dA", 3)
		}
	}

}
func j(a, b map[int]int) (c map[int]int) {
	c = make(map[int]int)
	for ka := range a {
		if _, ok := b[ka]; ok {
			c[ka] = 1
		}
	}
	return c
}
func b(a, b map[int]int) map[int]int {
	for ka := range a {
		b[ka] = 1
	}
	return b
}
func c(a, b map[int]int) map[int]int {
	for ka := range a {
		if _, ok := b[ka]; ok {
			delete(a, ka)
		}
	}
	return a
}
func testbuffer() {
	a := make([]byte, 3, 3)
	b := bytes.NewBuffer(a)
	b.WriteByte(1)
	fmt.Println(a)
	fmt.Println(b.Bytes())

}
func tp() {
	var a *int
	var d *int
	var b int
	var c int
	a = &b
	d = a
	a = &c
	fmt.Println(a, d)
}
func tbig() {
	var a = byte(4)
	var b = byte(5)
	var c = []byte{a, b}
	fmt.Println(binary.BigEndian.Uint16(c))
}
func tnil() {
	var a []int
	var b = a
	a = make([]int, 2, 2)
	copy(a, b)
	fmt.Println(a)
}
func trecover() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("Recovered in f", r)
		}
	}()

	panic("fuck")

	fmt.Println("what are you doing")
}
func main() {
	trecover()
	time.Sleep(time.Second * 1)
}
